/*
 * @lc app=leetcode.cn id=67 lang=javascript
 *
 * [67] 二进制求和
 */

// @lc code=start
/**
 * @param {string} a
 * @param {string} b
 * @return {string}
 */
var addBinary = function(a, b) {
    let ans=""
    let add=0
    let len=Math.max(a.length,b.length)
    while(b.length<len){b=0+b}
    while(a.length<len){a=0+a}
    for(let i=len-1;i>=0;i--){
        let charA=+a[i]
        let charB=+b[i]
        let sum=charA+charB+add
        let char=sum%2
        add=(sum/2)|0
        ans=char+ans
    }
    if(add!=0){ans=1+ans}
    return ans
    
};
// @lc code=end

